﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<div class="rows">
    <div class="panel panel-default">
        <table class="form">
            <tr>
                <th class="formTitle">年份：</th>
                <td class="formValue">
                    <select id="year" name="year" class="formClearIgnore">
                        <option value="">==请选择==</option>
                    </select>
                </td>
                <th class="formTitle">月份：</th>
                <td class="formValue">
                    <select id="month" name="month" class="formClearIgnore">
                        <option value="">==请选择==</option>
                    </select>
                </td>
                <td class="formValue" style="padding-left:20px;">
                    <input type="button" id="btn_search" class="btn btn-primary btn-md" value="查询" style="width:55px" />
                </td>
                <td class="formValue" colspan="2">
                    <input type="button" id="btn_gene" class="btn btn-primary btn-md" value="生成" style="width:55px;display:inline-block;display:none;" />
                    <input type="button" id="btn_regene" class="btn btn-warning btn-md" value="重新生成" style="display:inline-block;display:none;" />
                </td>
                <td class="formValue"></td>
            </tr>
        </table>
    </div>
</div>
<div class="ui-layout" id="layout" style="height:100%;width:100%;">
    <iframe class="ui-layout-center" style="width:100%;" id="iframerightiframerightiframerightttt" name="iframerightiframerightiframerightttt"
            scrolling="auto" allowtransparency="true" frameborder="0"></iframe>
</div>
<script type="text/javascript">
    //全局变量
    var orgId = '@(ViewBag.OrgId)';
    //ReportingService Host
    var reportServerHOST = '@(ViewBag.ReportServerHOST)';


</script>
<script type="text/javascript">
    //年月下拉初始化
    (function initYearMonthSelect() {
        var date = new Date;
        //默认选择上个月
        var defaultSelYear = 1900 + date.getYear();
        var defaultSelMonth = date.getMonth();
        if (defaultSelMonth == 0) {
            defaultSelYear--;
            defaultSelMonth = 12;
        }
        //年份
        $("#year").newtouchBindSelect({
            datasource: function () {
                var resultObjArr = new Array();
                if (top.clients.yearArr && top.clients.yearArr.length) {
                    $.each(top.clients.yearArr, function () {
                        resultObjArr.push({ id: this, text: this });
                    });
                }
                return resultObjArr;
            },
            selectedValue: defaultSelYear,
        });
        //月份
        $("#month").newtouchBindSelect({
            datasource: function () {
                var resultObjArr = new Array();
                if (top.clients.monthArr && top.clients.monthArr.length) {
                    $.each(top.clients.monthArr, function () {
                        resultObjArr.push({ id: this, text: parseInt(this) < 10 ? "0" + this : this });
                    });
                }
                return resultObjArr;
            },
            selectedValue: defaultSelMonth,
        });

    })();
</script>
<script type="text/javascript">
    var showType = "1";
    var submit = function () {
        $.najax({
            type: "GET",
            url: "/KPI/MedicalOrg/CheckIsGenerated?year=" + $('#year').val()
                + "&month=" + $('#month').val(),
            loading: true,
            loadingtext: '正在请求报表状态...',
            cache: false,
            success: function (ajaxresp) {
                if (ajaxresp.flag === false) {
                    showType = "2"  //未生成过
                }
                else {
                    showType = "1"  //当月已生成过固定报表
                }
                searchReport(); //查询报表
            }
        });
    };
    $('#btn_search').click(function () {
        newtouch_globalevent_f4();

        submit();
    });
    $("#iframerightiframerightiframerightttt").load(function () {
        $.loading(false);
        if (showType == "1") {
            $('#btn_regene').show();
            $('#btn_gene').hide();
        }
        else {
            $('#btn_gene').show();
            $('#btn_regene').hide();
        }
    });
</script>
<script type="text/javascript">
    //查询报表
    function searchReport() {
        var url = reportServerHOST + "ReportServer/Pages/ReportViewer.aspx?%2FHIS.Report.1%2FKPI.%E5%8C%BB%E7%96%97%E6%9C%BA%E6%9E%84%E6%9C%88%E5%9B%BA%E5%AE%9A%E6%8A%A5%E8%A1%A8&rs:Command=Render";

        //var url = reportServerHOST + "ReportServer/Pages/ReportViewer.aspx?%2FHIS.Report.1%2FKPI.治疗师月报表.已固定&rs:Command=Render";
        url += "&rc:Stylesheet=MyStyleSheet";
        url += "&orgId=" + orgId;
        url += "&year=" + $('#year').val();
        url += "&month=" + $('#month').val();

        if (showType == "1") {
            setTimeout("$.loading(true, '当月报表已生成过，正在呈现...');", 10);
        }
        else {
            setTimeout("$.loading(true, '当月报表尚未生成过，正在计算...');", 10);
        }

        $("#iframerightiframerightiframerightttt").attr('src', url);
    }
</script>
<script type="text/javascript">
    //生成报表
    $("#btn_gene").click(function () {
        ReqDoGenerate();
    });
    //重新生成报表
    $("#btn_regene").click(function () {
        $.modalConfirm("重新生成报表，确认继续？", function (flag) {
            if (flag) {
                ReqDoGenerate(true);
            }
        });
    });

    function ReqDoGenerate(isReGene) {
        $.najax({
            type: "POST",
            url: "/KPI/MedicalOrg/DoGenerate",
            data: { year: $('#year').val(), month: $('#month').val(), isReGene: isReGene },
            dataType: "json",
            loadingtext: "报表生成中，请稍后...",
            success: function (ajaxResp) {
                $.modalMsg('报表生成成功', 'success');
                setTimeout("$('#btn_search').trigger('click');", 1000); //重新查询报表
            }
        });
    }
</script>
<script type="text/javascript">
    $(function () {
        var h = $(window).height() - 55;
        $('#layout iframe').css('height', h);

    });
</script>
<script type="text/javascript">
    function newtouch_event_f4() {
        $('#btn_gene').hide();
        $('#btn_regene').hide();

    }
</script>
<script type="text/javascript">
    function funcOrganizeIdChange() {
        orgId = $("#OrganizeId").val();
        submit();
    }
</script>
@Html.Partial("_ReportOrganizeIdDDLSearchView")